package com.ihelp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ihelp.pojo.Hospital;
import com.ihelp.mapper.HospitalMapper;
import com.ihelp.pojo.User;
import com.ihelp.service.HospitalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiuZiMing
 * @since 2023-05-23
 */
@Service
public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements HospitalService {

    @Autowired
    private HospitalMapper hospitalMapper;
    @Override
    public List<Hospital> getAllHospital() {
        return hospitalMapper.selectList(null);
    }

    @Override
    public Hospital getHospitalById(Integer id) {
        return hospitalMapper.selectById(id);
    }

    @Override
    public List<Hospital> getHospitalByDynamicConditions(Integer id, String hospitalName, String position) {
        QueryWrapper<Hospital> hospitalQueryWrapper = new QueryWrapper();

        for (int i = 0; i < 1; i++) {
            if (id != null && id > 0) {
                hospitalQueryWrapper.eq("id", id);
            }
            if (hospitalName != null) {
                hospitalQueryWrapper.eq("hospital_name", hospitalName);
            }
            if (position != null) {
                hospitalQueryWrapper.eq("position", position);
            }
        }

        List<Hospital> hospitalList = hospitalMapper.selectList(hospitalQueryWrapper);
        return hospitalList;
    }
}
